home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / lu62 / novell / nwdrvn.asm < prev    next >
Assembly Source File  |  1996-07-10  |  14KB  |  450 lines

  1. ;********************************************************
  2. ;*                                                      *
  3. ;*                 N W D r v                            *
  4. ;*                                                      *
  5. ;*  Function : NetWare driver for processing "SEND",    *
  6. ;*             and "RECEIVE" operation.                 *
  7. ;*             This function is interrupt handler       *
  8. ;*             with number 6eh.                         *
  9. ;*  Input:     In AH contains function code.            *
  10. ;*             Function code may be:                    *
  11. ;*             TEST - test if int 6f handler is         *
  12. ;*                    active;                           *
  13. ;*             OPEN - open the socket for I/O           *
  14. ;*                    operation, and activate           *
  15. ;*                    interface functions. In DS:DX's   *
  16. ;*                    address of Input_Control_Record   *
  17. ;*                    (see drvicr.inc for detailes);    *
  18. ;*             CLOSE - close the socket;                *
  19. ;*             SEND - send block,                       *
  20. ;*                    DS:DX points the block for        *
  21. ;*                    transmittion;                     *
  22. ;*             DEACT - deactivisation of driver (reset  *
  23. ;*                     old INT 6fh handler and free     *
  24. ;*                     allocated memory.                *
  25. ;*             DS:DX points appropriate memory block.   *
  26. ;*  Output:    Condition code in AX.                    *
  27. ;*  Last modification: 92-12-01 17:08.                  *
  28. ;*                                                      *
  29. ;* CopyRight 1995. Nicholas Poljakov all rights reserved.*
  30. ;*                                                      *
  31. ;********************************************************
  32. .MODEL TINY
  33. .DOSSEG
  34.  
  35. include c:\lu62\novell\inc\ipxhdr.inc
  36. include c:\lu62\novell\inc\seg.inc
  37. include c:\lu62\novell\inc\drvicr.inc
  38. include c:\m61\include\macros.inc
  39.  
  40. EXTRN DrvSend : PROC
  41. EXTRN OffInt6f: WORD
  42. EXTRN SegInt6f: WORD
  43. EXTRN MyPSP : WORD
  44.  
  45. PUBLIC  int6f, Rcv_Exit, Rcv_off, ipxProc, CheckAddr, ipxECB, CancelECB
  46. PUBLIC  Rcv_seg, Codes, ExTable, bufArea, PStart, DrvOpen, OpExit
  47. PUBLIC  DrvClose, Deact, Dummy, RcvESR, RcvContin, PrepECB, DrvTest
  48. PUBLIC  ActLU, ActLuMsg, LocalS, StAddrCycl, CallDrvSend
  49.  
  50.  
  51. OPEN     EQU   00h
  52. SEND     EQU   01h
  53. CLOSE    EQU   02h
  54. DEACT    EQU   03h
  55. CHKADDR  EQU   04h
  56. TESTEX   EQU   33h
  57.  
  58.  
  59. .CODE
  60. int6f    PROC  FAR
  61.  
  62.          jmp   PStart
  63.  
  64. ipxProc  DD    0    ; IPX entry point
  65. Rcv_Exit DD    0
  66.          ORG   Rcv_Exit
  67. Rcv_off  DW    ?
  68. Rcv_seg  DW    ?
  69.  
  70. Codes    DB    OPEN,CLOSE,SEND,DEACT,CHKADDR,TESTEX,255
  71. Count    EQU   $ - Codes
  72. ExTable  DW    DrvOpen
  73.          DW    DrvClose
  74.          DW    DrvSend
  75.          DW    Deact
  76.          DW    CheckAddr
  77.          DW    DrvTest
  78.          DW    Dummy
  79.  
  80. ipxECB   IPXECB <>
  81. ipxHDR   IPXHDR <>
  82. ipxAddr  INTADDR <>     ; IPX internetwork address
  83. ImmAddr  DB  6 DUP(?)   ; Immediate Address of node.
  84. bufArea  DB 546 dup(0)
  85.  
  86. LocalS   DB    0        ; "Local_Send" indicator
  87. MsgFrom  DB    0        ; First byte of Node Address
  88. ActLuMsg SEGPRF <, 9, 0>
  89. RQB      DB    16 dup(0) ; reserved RQD field
  90. MsgTag   DB    1
  91. NameLu   DB    0,0,0,0,0,0,0,0 ; Activate LU message
  92.  
  93. PStart:
  94.          @SaveRegs ax,bx,cx,ds,dx,si,di,es,bp
  95.          mov   bp, sp
  96.  
  97.          sti
  98.          mov   cx, cs
  99.          mov   ds, cx
  100.          mov   cx, Count
  101.          mov   di, OFFSET Codes
  102.          push  cs
  103.          pop   es
  104.          mov   al, ah
  105.          cld
  106.          repne scasb
  107.          sub   di,(OFFSET Codes)+1   ; Point to key
  108.          shl   di,1                  ; Adjust pointer for word addresses
  109.          call  ExTable[di]           ; Call procedure
  110.          jc    IntExit               ; return code was already set.
  111.          mov   WORD PTR [bp + 16], ax ; set RETURN CODE in AX
  112.  
  113. IntExit:
  114.          @RestoreRegs
  115.          iret
  116.  
  117. int6f    ENDP
  118.  
  119. DrvOpen  PROC
  120. ;***************************************************
  121. ;*    First, fetch address of IPX entry point      *
  122. ;***************************************************
  123.  
  124.          mov   ax, 7a00h
  125.          int   2fh
  126.          cmp   al, 0ffh
  127.          je    IPXexist
  128.          mov   ax, 0ffffh
  129.          jmp   OpExit   ; in ax - bad return code
  130. IPXexist:
  131.          mov   ax, es
  132.          mov   WORD PTR ipxProc, di
  133.          mov   WORD PTR ipxProc + 2, ax
  134.  
  135. ;   Set Rcv_Exit value
  136.  
  137.          les   bx, DWORD PTR [bp + 8]   ; input DX value
  138.          mov   ax, WORD PTR es:[bx].RcvSbr
  139.          mov   Rcv_off, ax
  140.          mov   ax, WORD PTR es:[bx].RcvSbr + 2
  141.          mov   Rcv_seg, ax
  142.  
  143. ;***************************************************
  144. ;     Second, Open the socket...                   *
  145. ;***************************************************
  146.  
  147.          xor   bx, bx       ; open socket function
  148.          mov   ax, 0ffffh   ; open until closed
  149.          mov   dx, MY_SOCKET
  150.          call  ipxProc
  151.          and   ax, ax       ; is it O.K! ?
  152.          jnz   OpExit       ; no... exit.
  153.  
  154. ;***************************************************
  155. ;*   Then  send "Activate_LU" broadcasting message *
  156. ;*   and set "listening" request                   *
  157. ;***************************************************
  158.  
  159.          call  ActLU
  160.          call  PrepECB
  161.  
  162. ;  And exit...
  163.  
  164. OpExit:
  165.          clc
  166.          ret
  167. DrvOpen  ENDP
  168.  
  169. DrvClose PROC
  170.  
  171. ;  Close my socket
  172.  
  173.          mov   bx, 1
  174.          mov   dx, MY_SOCKET
  175.          call  ipxProc
  176.  
  177.          clc
  178.          ret
  179. DrvClose ENDP
  180.  
  181. ;***************************************************
  182. ;*                                                 *
  183. ;*     Deactivation LU procedure.                  *
  184. ;*                                                 *
  185. ;*  Function : 1). Sends broadcasting message      *
  186. ;*                 "Deactivate_LU".                *
  187. ;*             2). Close socket.                   *
  188. ;*             3). Restore pointer to old INT 6fh  *
  189. ;*                 handler.                        *
  190. ;*             4) And free the memory allocated for*
  191. ;*                this program.                    *
  192. ;*                                                 *
  193. ;***************************************************
  194. Deact    PROC
  195. ;*
  196. ;*  Send broadcasting "Deactivisation_LU" message
  197. ;*
  198.          mov   ipxHDR.PType, 0    ; control packet
  199.          mov   MsgTag, 2
  200.          call  ActLU
  201.  
  202. ;*  Close my socket
  203.  
  204.          mov   bx, 1
  205.          mov   dx, MY_SOCKET
  206.          call  ipxProc
  207. ;*
  208. ;*  Restory Old Int6fh vector
  209. ;*
  210.          cli
  211.          mov   ax, 10h
  212.          mov   es, ax
  213.          mov   ax, OffInt6f
  214.          mov   WORD PTR es:[0bch], ax  ; Old INT6f, offset
  215.          mov   ax, SegInt6f
  216.          mov   WORD PTR es:[0beh], ax  ; Old INT6f, segment
  217.          sti
  218.  
  219. ;*
  220. ;*  And free program segment...
  221. ;*
  222.          mov   ax, MyPSP
  223.          mov   es, ax
  224.          mov   ax, 4900h
  225.          int   21h        ; Free code segment
  226.  
  227.          clc
  228.          ret
  229. Deact    ENDP
  230.  
  231. Dummy    PROC
  232.          clc
  233.          ret
  234. Dummy    ENDP
  235.  
  236. CheckAddr PROC
  237. ;***************************************************
  238. ;*                                                 *
  239. ;*   Check Node address before send block to it.   *
  240. ;*                                                 *
  241. ;***************************************************
  242.  
  243.           les  bx, DWORD PTR [bp + 8]  ; input DS:DX values
  244.  
  245. ;         Prepare Address buffer
  246.  
  247.           mov  ax, WORD PTR es:[bx]
  248.           mov  WORD PTR ipxAddr.NodeAddr, ax
  249.           mov  ax, WORD PTR es:[bx + 2]
  250.           mov  WORD PTR ipxAddr.NodeAddr + 2, ax
  251.           mov  ax, WORD PTR es:[bx + 4]
  252.           mov  WORD PTR ipxAddr.NodeAddr + 4, ax
  253.           mov  si, OFFSET ipxAddr
  254.           mov  di, OFFSET ImmAddr
  255.           mov  bx, cs
  256.           mov  es, bx
  257.           mov  bx, 2
  258.           call ipxProc  ; get local target for input node address
  259.           xor  ah, ah
  260.           and  ax, ax   ; check return code from IPX
  261.           jnz  ChkExit  ; bad return code... exit.
  262.  
  263.           mov  di, WORD PTR [bp + 8]   ; input DX value
  264.           mov  ax, WORD PTR [bp + 12]  ; input DS value
  265.           mov  es, ax
  266.           mov  si, OFFSET ImmAddr
  267.           mov  cx, cs
  268.           mov  ds, cx
  269.           mov  cx, 6
  270.           cld
  271.           rep  movsb    ; copy returned address to field
  272.                         ; that pointes by input DS:DX
  273.           xor  ax, ax   ; O.K! return code
  274.  
  275. ChkExit:
  276.           clc
  277.           ret
  278. CheckAddr ENDP
  279.  
  280.  
  281. ;***************************************************
  282. ;*                                                 *
  283. ;*   ESR for receiving incoming packet.            *
  284. ;*   ES:SI points to appropriate ECB.              *
  285. ;*   AX - source indicator                         *
  286. ;*                                                 *
  287. ;***************************************************
  288. RcvESR   PROC  FAR
  289.          cli
  290.          mov   cx, cs
  291.          mov   ds, cx
  292.  
  293.          cmp   ipxECB.RetCode,0 ; is it normal receive ?
  294.          jne   RcvContin
  295.          les   di, ipxECB.SAddr ; address of data block
  296.          mov   cl, BYTE PTR es:[di] ; first byte of Network Address
  297.          mov   MsgFrom, cl      ; Save first byte of Node address
  298.          lea   si, ipxECB.PAddr ; pointer to partner address field
  299.          mov   cx, 6
  300.          cld
  301.          rep   movsb            ; mov p. addr. in SEGPRF.PAddr
  302.          les   si, ipxECB.FAddr ; ES:SI pointes to IPX header
  303.          mov   cx, es:[si].PLt  ; total length of received data block
  304.          xchg  ch, cl
  305.          sub   cx, 30           ; length of data block
  306.          mov   dx, WORD PTR ipxECB.SAddr
  307.          mov   ax, WORD PTR ipxECB.SAddr + 2
  308.          xor   bh, bh
  309.          mov   bl, ipxHDR.PType ; packet type
  310.          push  ds
  311.          mov   ds, ax           ; DS:DX now points to input buffer
  312.          mov   ax,  bx          ; message type indicator
  313.          pushf                  ; Call "_interrupt" function for read block
  314.          call  Rcv_Exit
  315.          pop   ds
  316.          and   bx, bx           ; is it a control message ?
  317.          jnz   RcvContin        ; no...
  318.          les   bx, ipxECB.SAddr ; ES:BX points to message field
  319.          cmp   BYTE PTR es:[bx + PRFLT], 2  ; is it "Deactivate_LU" message ?
  320.          je    RcvContin
  321.          cmp   MsgFrom, 0ffh    ; is it broadcasting message ?
  322.          jne   RcvContin
  323.          mov   si, bx
  324.          mov   di, OFFSET ActLuMsg
  325.          mov   cx, 6
  326.          cld
  327.          rep   movsb            ; set address of source of message
  328.          call  ActLU            ; send response to "Activate_Lu"
  329.                                 ; message
  330.  
  331. RcvContin:
  332.          call  PrepECB
  333.  
  334.          ret
  335. RcvESR   ENDP
  336.  
  337. PrepECB  PROC
  338.  
  339. ;     Prepare ECB for receivig packets
  340.  
  341.          cmp   ipxECB.InUse, 0feh          ; is ECB in listening mode?
  342.          je    PrepExit
  343.          mov   ax, OFFSET RcvESR
  344.          mov   WORD PTR ipxECB.ESR, ax     ; set ESR address
  345.          mov   ax, cs                      ; for
  346.          mov   WORD PTR ipxECB.ESR + 2, ax ; block receiving
  347.          mov   ipxECB.SocNum, MY_SOCKET
  348.          mov   bx, OFFSET ipxHDR
  349.          mov   WORD PTR ipxECB.FAddr, bx   ; set ipx header address
  350.          mov   WORD PTR ipxECB.FAddr + 2, ax
  351.          mov   ipxECB.FLt, 30              ; length of ipx header
  352.          mov   bx, OFFSET bufArea
  353.          mov   WORD PTR ipxECB.SAddr, bx   ; set address of data block
  354.          mov   WORD PTR ipxECB.SAddr + 2, ax
  355.          mov   ipxECB.SLt, 546             ; length of data block
  356.          mov   ipxECB.FragNum, 2           ; two fragments
  357.  
  358.          mov   bx, cs
  359.          mov   es, bx
  360.          mov   bx, 4
  361.          mov   si, offset ipxECB
  362.          call  ipxProc
  363.  
  364. PrepExit:
  365.          ret
  366. PrepECB  ENDP
  367.  
  368. DrvTest  PROC
  369.          mov   WORD PTR [bp + 16], 5555h ; set output AX value
  370.                                          ; 5555h - indicates that
  371.                                          ; int 6fh is exist.
  372.          xor   ax, ax                    ; local return code
  373.          stc                             ; to prevent reset
  374.                                          ; global return code
  375.          ret
  376. DrvTest  ENDP
  377.  
  378. CancelECB PROC
  379.      @SaveRegs ax,bx,cx,si,es
  380. CnPrep:
  381.          mov   si, cs
  382.          mov   es, si
  383.          mov   si, OFFSET ipxECB
  384.          mov   bx, 6    ; cancel request
  385.          call  ipxProc
  386.          and   al, al
  387.          jz    CnExit
  388.          cmp   al, 0ffh
  389.          je    CnExit
  390.          cmp   al, 0ffh
  391.          jne   CnExit
  392.  
  393.          mov   cx, 0ffffh
  394.          sti
  395. WaitCycl:
  396.          loop  WaitCycl ; wait for end of transmittion
  397.          jmp   short CnPrep
  398.  
  399. CnExit:
  400.      @RestoreRegs
  401.          ret
  402. CancelECB ENDP
  403.  
  404. ;***************************************************
  405. ;*                                                 *
  406. ;*         Activate LU procedure.                  *
  407. ;* Function: Send broadcasting "Activate_LU"       *
  408. ;*           message.                              *
  409. ;*                                                 *
  410. ;***************************************************
  411.  
  412. ActLU    PROC
  413.  
  414. ; Set address of broadcasting message.
  415.  
  416.          cmp   ipxHDR.PType, 0    ; is it response to control message?
  417.          je    CallDrvSend        ; yes, skip address and name setting
  418.  
  419.          mov   bx, OFFSET ActLuMsg
  420.          mov   cx, 6
  421. StAddrCycl:
  422.          mov   BYTE PTR cs:[bx], 0ffh
  423.          inc   bx
  424.          loop  StAddrCycl
  425.  
  426. ; Set Lu_Name field in "Activate_LU" message.
  427.  
  428.          lds   si, DWORD PTR [bp + 8]  ; input DS:DX values
  429.          lea   si, ds:[si].LuName
  430.          mov   di, cs
  431.          mov   es, di
  432.          mov   di, OFFSET NameLu
  433.          mov   cx, 8
  434.          cld
  435.          rep   movsb        ; move LU name begins to RH + 1 location
  436.          mov   ax, cs
  437.          mov   ds, ax
  438.  
  439. ; Call "DrvSend function".
  440.  
  441. CallDrvSend:
  442.          mov   LocalS, 1     ; ON a "local_send" operation
  443.          call  DrvSend
  444.          mov   LocalS, 0     ; OFF a "local_send" operation
  445.  
  446.          ret
  447. ActLU    ENDP
  448.  
  449.          END
  450.